namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class LegendFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Legend>()
                .DerivesFrom<Element>()
                .IsConcreteClass()
                .IsUnsealed()
                .HasDefaultConstructor()
                .Implements<IAttributeAccesskey>()
                .Implements<IXmlSerializable>()
                .XmlRoot("legend")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            Legend expected = new Legend
            {
                Id = "id",
                Accesskey = 'a',
                Class = "class",
                Language = "fr",
                Title = "title"
            };

            string xml = "<legend id='id' class='class' lang='fr' title='title' accesskey='a' />";
            Legend actual = xml.Deserialize<Legend>();

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }

        [Fact]
        public void deserializeEmpty()
        {
            Assert.NotNull("<legend />".Deserialize<Legend>());
        }

        [Fact]
        public void serialize()
        {
            Legend obj = new Legend
            {
                Id = "id",
                Accesskey = 'a',
                Class = "class",
                Language = "fr",
                Title = "title"
            };

            string xpath = "1=count(/legend[@accesskey='a'][@id='id'][@class='class'][@lang='fr'][@title='title'])";

            Assert.True((bool)obj.Serialize().CreateNavigator().Evaluate(xpath));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Legend());
        }

        [Fact]
        public void prop_Accesskey()
        {
            Assert.True(new PropertyExpectations(typeof(Legend).GetProperty("Accesskey"))
                .IsAutoProperty<char?>()
                .Result);
        }

        [Fact]
        public void prop_Title()
        {
            Assert.True(new PropertyExpectations(typeof(Legend).GetProperty("Title"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            Legend expected = new Legend
            {
                Id = "id",
                Accesskey = 'a',
                Class = "class",
                Language = "fr",
                Title = "title"
            };

            string xml = "<legend id='id' class='class' lang='fr' title='title' accesskey='a' />";
            Legend actual = new Legend().Deserialize("legend", null, xml) as Legend;

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }
    }
}